package Euler35;

import java.util.*;
import ReusableCode.*;

public class CircularPrime {

	public static void main(String[] args) {
		List<Integer> primes = PrimeFunctions.GetPrimes(1000000);
		HashMap<Integer, Boolean> circularPrimes = new HashMap<Integer, Boolean>();
		
		for(int i = 0; i < primes.size(); i++)
		{
			int prime = primes.get(i);
			if(circularPrimes.containsKey(prime))
			{
				continue;
			}
			else
			{
				int[] digits = MathFunctions.getDigits(prime);
				boolean passed = true;
				
				for(int j = 0; j < digits.length; j++)
				{
					if(digits[j] == 5 || digits[j] % 2 == 0)
					{
						passed = false;
						break;
					}
				}
				
				if(!passed)
				{
					continue;
				}
				
				List<Long> perms = MathFunctions.getNumberRotations(prime);
				System.out.println(perms);
				for(int j = 0; j < perms.size(); j++)
				{
					if(Collections.binarySearch(primes, MathFunctions.safeLongToInt(perms.get(j)))<0)
					{
						passed = false;
						break;
					}
				}
				
				if(passed)
				{
					for(int j = 0; j < perms.size(); j++)
					{
						if(!circularPrimes.containsKey(MathFunctions.safeLongToInt(perms.get(j))))
							circularPrimes.put(MathFunctions.safeLongToInt(perms.get(j)), true);
					}
				}
			}
		}
		
		System.out.println(circularPrimes);
		System.out.println(circularPrimes.values().size());
	}
}
